package com.aier.service.rights.impl;


import com.aier.bean.common.GlobalCode;
import com.aier.bean.staff.StaffInfo;
import com.aier.exception.CastException;
import com.aier.mapper.staff.StaffInfoMapper;
import com.aier.service.rights.StaffInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 员工service实现类
 */
@Service
public class StaffInfoServiceImpl implements StaffInfoService {

    @Autowired
    private StaffInfoMapper staffInfoMapper;

    @Override
    public void saveStaff(StaffInfo staffInfo) {
        staffInfoMapper.insert(staffInfo);
    }

    @Override
    public StaffInfo getStaffInfoByAccountAndPsd(String account, String password) {
        QueryWrapper<StaffInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(StaffInfo::getAccount,account)
                .eq(StaffInfo::getPassword,password);
        StaffInfo staffInfo = staffInfoMapper.selectOne(queryWrapper);
        if (staffInfo == null) CastException.cast(GlobalCode.ACCOUNT_PASSWORD_ERROR);
        return staffInfo;
    }
}
